﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LoveEat.API.Write.Controllers
{
    /// <summary>
    /// API控制器—图片上传
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PhotoController : ControllerBase
    {
        /// <summary>
        /// 图片上传方法
        /// </summary>
        /// <param name="file">文件</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public IActionResult Img(IFormFile file)
        {
            var list=Directory.GetCurrentDirectory()+@"/wwwroot/Goods/"+file.FileName;
            using (FileStream ms = new FileStream(list, FileMode.Create))
            {
                file.CopyTo(ms);
                ms.Flush();
            }
            return Ok("http://localhost:5164/Goods/" + file.FileName);
        }
        /// <summary>
        /// 图片上传方法（文件夹）
        /// </summary>
        /// <param name="file">文件</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public IActionResult Img2(IFormFile file)
        {
            var list = Directory.GetCurrentDirectory() + @"/wwwroot/Paths/" + file.FileName;
            using (FileStream ms = new FileStream(list, FileMode.Create))
            {
                file.CopyTo(ms);
                ms.Flush();
            }
            return Ok("http://localhost:5164/Paths/" + file.FileName);
        }

    }
}
